<%= turbo_frame_tag dom_id(cluster, "build_cloud") do %>
  <div class="card bg-base-200">
    <div class="card-body">
      <h3 class="text-lg font-bold flex items-center gap-2 mb-4">
        <iconify-icon icon="lucide:settings" height="20"></iconify-icon>
        Configure your build cloud environment
      </h3>

      <%= form_with model: build_cloud, url: cluster_build_cloud_path(cluster), method: :patch do |form| %>
        <div class="space-y-8">
          <div class="form-control">
            <div class="font-medium flex items-center gap-2 font-bold mb-4">
              <iconify-icon icon="lucide:server" height="20"></iconify-icon>
              <span>Replicas</span>
            </div>

            <%= form.number_field :replicas, 
                class: "input input-bordered w-full", 
                min: 1, max: 10,
                placeholder: "2" %>
            <div class="label">
              <span class="label-text-alt text-gray-500">Number of parallel builders (1-10)</span>
            </div>
          </div>

          <div class="space-y-4">
            <div class="font-medium flex items-center gap-2 font-bold">
              <iconify-icon icon="lucide:cpu" height="20"></iconify-icon>
              <span>CPU Configuration</span>
            </div>

            <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
              <div class="form-control">
                <%= form.label :cpu_requests, class: "label" do %>
                  <span class="label-text font-medium">CPU Request (millicores)</span>
                <% end %>
                <%= form.number_field :cpu_requests, 
                    class: "input input-bordered w-full", 
                    min: 100, step: 100,
                    placeholder: "500" %>
                <div class="label flex justify-between">
                  <span class="label-text-alt text-gray-500">
                    The minimum amount of CPU the build cloud will request.
                  </span>
                  <span class="label-text-alt text-gray-500">
                    Current: <%= integer_to_compute(build_cloud.cpu_requests) %>
                  </span>
                </div>
              </div>

              <div class="form-control">
                <%= form.label :cpu_limits, class: "label" do %>
                  <span class="label-text font-medium">CPU Limits (millicores)</span>
                <% end %>
                <%= form.number_field :cpu_limits, 
                    class: "input input-bordered w-full", 
                    min: 100, step: 100,
                    placeholder: "2000" %>
                <div class="label flex justify-between">
                  <span class="label-text-alt text-gray-500">The maximum amount of CPU the build cloud can use.</span>
                  <span class="label-text-alt text-gray-500">
                    Current: <%= integer_to_compute(build_cloud.cpu_limits) %>
                  </span>
                </div>
              </div>
            </div>
          </div>

          <div class="space-y-4">
            <div class="font-medium flex items-center gap-2 font-bold">
              <iconify-icon icon="lucide:hard-drive" height="20"></iconify-icon>
              <span>Memory Configuration</span>
            </div>
            <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
              <div class="form-control">
                <%= form.label :memory_requests, class: "label" do %>
                  <span class="font-medium text-sm">Memory Request (bytes)</span>
                <% end %>
                <%= form.number_field :memory_requests, 
                    class: "input input-bordered w-full", 
                    min: 134217728, step: 134217728,
                    placeholder: "536870912" %>
                <div class="label flex justify-between">
                  <span class="label-text-alt text-gray-500">
                    The minimum amount of memory the build cloud will request.
                  </span>
                  <span class="label-text-alt text-gray-500">
                    Current: <%= integer_to_memory(build_cloud.memory_requests) %>
                  </span>
                </div>
              </div>

              <div class="form-control">
                <%= form.label :memory_limits, class: "label" do %>
                  <span class="label-text font-medium">Memory Limits (bytes)</span>
                <% end %>
                <%= form.number_field :memory_limits, 
                    class: "input input-bordered w-full", 
                    value: build_cloud.memory_limits,
                    min: 134217728, step: 134217728,
                    placeholder: "4294967296" %>
                <div class="label flex justify-between">
                  <span class="label-text-alt text-gray-500">
                    The maximum amount of memory the build cloud can use.
                  </span>
                  <span class="label-text-alt text-gray-500">
                    Current: <%= integer_to_memory(build_cloud.memory_limits) %>
                  </span>
                </div>
              </div>
            </div>
          </div>
        </div>

        <div class="alert alert-warning mt-6">
          <iconify-icon icon="lucide:alert-triangle" height="20"></iconify-icon>
          <span>Changes will require reinstalling the build cloud to take effect.</span>
        </div>
        <div class="card-actions justify-end mt-6">
          <%= link_to cluster_build_cloud_path(cluster), 
                      class: "btn btn-ghost",
                      data: { turbo_frame: dom_id(cluster, "build_cloud") } do %>
            Cancel
          <% end %>
          <%= form.submit "Save Configuration", class: "btn btn-primary" %>
        </div>
      <% end %>

    </div>
  </div>
<% end %>